package com.hw.controller.order;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hw.entity.dto.order.OrderDTO;
import com.hw.entity.dto.order.OrderHistoryDTO;
import com.hw.entity.query.order.HistoryOrderQuery;
import com.hw.entity.query.order.OrderQuery;
import com.hw.entity.vo.order.HistoryOrderVO;
import com.hw.entity.vo.order.OrderListVO;
import com.hw.model.ResponseResult;
import com.hw.service.order.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单表 Controller
 *
 * @author xuguang
 * @date 2021-06-28
 */
@Api(tags = "用户订单")
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @ApiOperation(value = "获取以菜品为单位的用户信息")
    @GetMapping("/getUserAndFoodByOrder")
    public ResponseResult<?> getUserAndFoodByOrder(String taskId) {
        return ResponseResult.success(orderService.getUserAndFoodByOrder(taskId));
    }

    @ApiOperation(value = "获取当前用户的历史订单")
    @PostMapping("/getList")
    public ResponseResult<IPage<OrderListVO>> getList(@RequestBody OrderQuery orderQuery) {
        return ResponseResult.success(orderService.getList(orderQuery));
    }

    @ApiOperation(value = "保存订单")
    @PostMapping("/saveOrder")
    public ResponseResult<?> saveOrder(@RequestBody List<OrderDTO> orderDTOS) {
        return ResponseResult.success(orderService.saveOrder(orderDTOS));
    }

    @ApiOperation(value = "获取历史点餐详情")
    @GetMapping("/getHistoryInfo")
    public ResponseResult<List<HistoryOrderVO>> getHistoryInfo9(HistoryOrderQuery historyOrderQuery) {
        return ResponseResult.success(orderService.getHistoryInfo(historyOrderQuery));
    }

    @ApiOperation(value = "获取当前用户当前点餐码的总价格")
    @GetMapping("/getTotalPrice")
    public ResponseResult<?> getTotalPrice(String taskId) {
        return ResponseResult.success(orderService.getTotalPrice(taskId));
    }

    @ApiOperation(value = "保存历史详情更改")
    @PostMapping("/saveHistoryChange")
    public ResponseResult<?> saveHistoryChange(@RequestBody List<OrderHistoryDTO> orderHistoryDTOS) {
        return ResponseResult.success(orderService.saveHistoryChange(orderHistoryDTOS));
    }

}
